using System;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Schema;

namespace OpenComposite.Mapper
{
	public partial class FormTest : Form
	{
		public FormTest()
		{
			InitializeComponent();
		}

		private void mapper_ClientSizeChanged(object sender, EventArgs e)
		{

		}

		private void loadSourceToolStripMenuItem_Click(object sender, EventArgs e)
		{
			//if ( openXSDFile.ShowDialog() == DialogResult.OK ) {
			//    mapper.SourceSchema = loadSchema(openXSDFile.FileName);
			//}
		}

		private void loadTargetToolStripMenuItem_Click(object sender, EventArgs e)
		{
			//if ( openXSDFile.ShowDialog() == DialogResult.OK ) {
			//    mapper.TargetSchema = loadSchema(openXSDFile.FileName);
			//}
		}

		private void xmlschemaread_ValidationCallback(object sender, ValidationEventArgs e)
		{
			MessageBox.Show(e.Message);
		}

		private void generateXSLTToolStripMenuItem_Click(object sender, EventArgs e)
		{
			string mapping;
			XsltDocument xslt = mapper.GenerateXslt(out mapping);
			formXmlViewer dlg = new formXmlViewer();
			dlg.XmlDocument = xslt;
			dlg.ShowDialog();
		}
		private XmlSchema loadSchema(string filename)
		{
			XmlSchema xsd = null;
			using ( XmlTextReader xr = new XmlTextReader(filename) ) {
				xsd = XmlSchema.Read(xr, new ValidationEventHandler(xmlschemaread_ValidationCallback));
			}
			return xsd;
		}
	}
}